package com.spm.librarianmanagersystem.controller;

import com.alibaba.fastjson.JSONObject;
import com.spm.librarianmanagersystem.service.ReservationService;
import com.spm.librarianmanagersystem.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
public class DelayTaskController {
    @Autowired
    ReservationService rs;

    // 过程3 消费者调用这个API？
    @PostMapping("/api/callSomething")
    public JsonResult<Boolean> tobeCall(@RequestBody JSONObject obj) {
        System.out.println(LocalDateTime.now() + "_过程3请求的请求体： " + obj);
        try {
            JSONObject msg = obj.getJSONObject("msg");
            Boolean aBoolean = rs.cancelReser(msg.getInteger("currReserId"), msg.getString("currUserId"));
            return new JsonResult<>(aBoolean);
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult<>(false, 1, e.getMessage());
        }
    }

}
